<?php
/**
 * 个人用户登录接口控制器类
 * User: 苏近之
 * Date: 2019-03-24
 * Time: 02:03
 */

namespace app\user\controller;

use app\common\base\ApiController;
use app\common\exception\RequestParamsVerifyFailed;
use app\user\service\PersonLoginService;
use app\user\validator\PersonLoginPassword;
use think\facade\Request;

class PersonLogin extends ApiController
{

    /**
     * 使用密码登录
     * @throws
     */
    public function password()
    {
        $requestParams = Request::post();
        $validator = new PersonLoginPassword();
        if (!$validator->check($requestParams)) {
            throw new RequestParamsVerifyFailed($validator->getError());
        }
        $token = PersonLoginService::usePassword($requestParams['loginAccount'], $requestParams['password']);

        return $this->responseWithJson($token);
    }
}